$(function(){
	queryGroup();
})
//查询考勤组
var ajaxTable;
function queryGroup(){
	ajaxTable = ajaxUtil.dataTablesAjax("attendanceGroupTable",10,"dingTalk/queryGroup",
			{},[
			{"data":"groupName"},
			{"data":"participant"},
			{"data":"attendanceType",render:function(data){
				switch(data){
				case '0':return '固定班制';break;
				case '1':return '排班制';break;
				case '2':return '自由工时';break;
				}
			}},
			{"data":"workingDays",render:function(data){
				var arr = data.split(",");
				var newArr = [];
				var newStr = [];
				var weekArr = ['一','二','三','四','五','六','日'];
				for(var i=0,len=arr.length;i<len;i++){
					var sss = newArr.indexOf(arr[i]);
					if(sss>-1){
						newStr[sss]+=weekArr[i]+"、";
					}else{
						newArr.push(arr[i]);
						newStr[newArr.indexOf(arr[i])]=weekArr[i]+"、";
					}
				}
				var html = "";
				for(var j=0,leng=newArr.length;j<leng;j++){
					var temp = newStr[j].substring(0,newStr[j].length-1);
					newArr[j] = newArr[j]==""?"休息":newArr[j];
					html += "每周"+temp+" 班次"+newArr[j]+"<br/>";
				}
				return html;
			}},
			{"data":"id",render:function(data){
			   return "<button class='edit-btn btn btn-secondary radius' type='button' value='"+data+"'>编辑</button>&nbsp;<button class='delete-btn btn btn-danger radius' type='button' value='"+data+"'>删除</button>";
			} }
	]);
	layer.msg("查询完成",{icon:1});
	//点击编辑按钮时
	$("#attendanceGroupTable").on("click",".edit-btn",function(){
		var value = $(this).attr("value");
		window.location="groupSet.html?value="+value+"";
	});
	//点击删除按钮时
	$("#attendanceGroupTable").on("click",".delete-btn",function(){
		var id = $(this).val();
		if(confirm("确定删除该考勤组?")){
			ajaxUtil.ajaxRequest("dingTalk/deleteGroup",{"id":id})
				.then(function(data){
						ajaxTable.ajax.reload(null,false);
				});
		}
	});
}
